//
//  UIBarButtonItem+extensions.swift
//  YFSwiftWeibo
//
//  Created by tsaievan on 2017/8/24.
//  Copyright © 2017年 tsaievan. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    convenience init?(title: String, fontSize: CGFloat = 16, target: AnyObject?, action: Selector, isBack: Bool = false) {
        guard let btn: UIButton = UIButton.hm_textButton(withTitle: title, fontSize: fontSize, normalColor: UIColor.orange, highlightedColor: UIColor.darkGray) else {
            return nil
        }
        
        if isBack {
            let imageName = "navigationButtonReturn"
            btn.setImage(UIImage(named: imageName), for: .normal)
            btn.setImage(UIImage(named: imageName + "Click"), for: .highlighted)
            btn.sizeToFit()
        }
        
        btn.addTarget(target, action: action, for: .touchUpInside)
        ///< 实例化UIBarButtonItem
        self.init(customView: btn)
    }
}
